import pageination from '../../components/pageination/pageination.vue'
export default {
	data() {
		return {
			//数据
      temApplicationStatus: false,
      thatUrl: this.urls.baseUrl,
      Application: false, // 基地详情弹框
      FileUploads: [], //申请退出的附件
      base: {}, // 基地详情
      reasonFile: '', // 不通过附件
      userId: '',
      baseId: '',
      status: '', // 申请事项
      user: [],
      baseData: [], // 基地数据
			modelShow: false,
			ProjectModelShow: false,  // 不通过的弹框
			demandModelShow: false,
			WorkModelShow: false,
			total: 0, //总条数
			page: 1, //当前页
			size: 10, //每页显示条数
			uploadNum: 0,
			FileUpload: [],
			curId: 0,
      upage: 0,
      usize: 10,
      utotal: 0
		}
	},
	components: {
		pageination
	},
	created() { //调用方法
	},
	mounted() {

  },
	methods: { //写函数方法
	  // 提交
    subBase: function () {
      let that = this;

      if(! that.userId){
        layer.msg('请选择基地负责人!', {
          time: 3000, //3s后自动关闭
        });
        return;
      }

      let obj = {};
       if(that.status == 2){
         obj = {"id": that.baseId, "status": 0};
       }else {
         obj = {"id": that.baseId, "status": 1, "userId": that.userId};
       }

  /*    that.$post(
        that.urls.baseQueryHeavy,
           obj
      )
        .then(function(res) {

          if(res.success && res.data) {
            layer.msg(res.data, {
              time: 3000, //3s后自动关闭
            });
          }else {*/

            that.$post(
              that.urls.editBaseAreas,
              obj
            )
              .then(function(res) {
                if(res.success) {
                  layer.msg('成功分配基地负责人!', {
                    time: 3000, //3s后自动关闭
                  });
                  that.demandModelShow = false;
                  that.initBase();
                }else {
                  layer.msg('分配基地负责人失败!', {
                    time: 3000, //3s后自动关闭
                  });
                }
              })

       /*   }
        })*/


    },
		//页码切换执行方法
		pageFn: function(val, pid) {
			this.page = parseInt(val);
			this.initBase();
			//此处调列表数据接口
		},
		/**返回子组件用户选择的一页显示条数**/
		obtainChild: function(data) {
			this.row = data;
		},

    pageFn1: function(val, pid) {
      this.upage = parseInt(val);
      this.getAllUser();
      //此处调列表数据接口
    },
    /**返回子组件用户选择的一页显示条数**/
    obtainChild1: function(data) {
      this.row = data;
    },

		touchOffIdInput(n) {
			this.uploadNum = n;
			if(n == 1) {
				$("#handIdFront").click();
			}
		},
    /**文件上传(多文件)js**/
    idFrontImg: function(event) {
      let that = this;
      let files = event.currentTarget.files;
      if (!that.fileGlobalFilter(files)) {
        return;
      }
      let formData = new FormData();
      for(let i = 0, len = files.length; i < len; i++) {
        formData.append('fileNames', files[i]);
      }
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data;boundary = ' + new Date().getTime()
        }
      };
      that.$post(
        that.urls.upload,
        formData,
        config
      )
        .then(function(res) {
          if(res.success) {
            let fileInfos = res.data;
            let urls = [];
            let names = [];
            for(let i = 0, len = fileInfos.length; i < len; i++) {
              urls.push(fileInfos[i].url);
              names.push(that.getFileName(fileInfos[i].url));
            }
            that.FileUpload = names;
            that.reasonFile = urls.join(";");
          }
        })
      console.log(that.FileUpload )
    },

		// 基地申请详情
		projectDetails: function(id) {
      let that = this;
      that.Application = true;
      this.base.picture="";
      that.$post(
        that.urls.getBaseAreas,
        {"id": id}
      )
        .then(function(res) {
          if(res.success) {
            that.base = res.data;

            let picList = [];
            picList.push({
              "name": that.getFileName(that.getFileName(res.data.quitFile)),
              "url": that.urls.baseUrl + res.data.quitFile
            });
            that.FileUploads = picList;

          }
        })
		},
		// 基地申请  同意
		demand: function(id, status) {
		  let that = this;
		  that.baseId = id;
		  that.status = status;
		  console.log(id)
      that.upage = 1;
      that.getAllUser();
			this.demandModelShow = true;
		},

    // 基地申请  不同意
    unmadn: function (id) {
      let that = this;
      that.$post(
        that.urls.editBaseAreas,
        {"id": id, "status": 0}
      )
        .then(function(res) {
          if(res.success) {
            layer.msg('成功审核不通过', {
              time: 3000, //3s后自动关闭
            });
            that.initBase();
          }else {
            layer.msg('审核不通过失败', {
              time: 3000, //3s后自动关闭
            });
            }
        })
    },

    // 申请退出 同意
    unDemand: function(id) {
      let that = this;
      that.baseId = id;

      that.$post(
        that.urls.editBaseAreas,
        {"id": id, "status": 3}
      )
        .then(function(res) {
          if(res.success) {
            layer.msg('基地退出申请已通过!', {
              time: 3000, //3s后自动关闭
            });
            that.initBase();
          }else {
            layer.msg('基地退出申请不通过!', {
              time: 3000, //3s后自动关闭
            });
          }
        })

    },

    // 退出不通过弹出弹框
     theDem: function (id) {
      this.baseId = id;
       this.ProjectModelShow = true;
     },

    // 退出不通过 提交
    unSubData: function () {
      let that = this;
      if(!$('#reason').val()){
        layer.msg('请填写不通过原因!', {
          time: 3000, //3s后自动关闭
        });
        return;
      }

      if($('#reason').val().length > 100 ){
        layer.msg('内容最多只能100个字!', {
          time: 3000, //3s后自动关闭
        });
        return;
      }

      that.$post(
        that.urls.editBaseAreas,
        {"id": that.baseId, "status": 5,"reasonFile": that.reasonFile, "reason": $('#reason').val() }
      )
        .then(function(res) {
          if(res.success) {
           that.ProjectModelShow = false;
            layer.msg('成功审核不通过!', {
              time: 3000, //3s后自动关闭
            });
            that.initBase();
          }else {
            layer.msg('审核不通过失败!', {
              time: 3000, //3s后自动关闭
            });
          }
        })
    },




		//关闭模态框
		closeModel: function() {
      this.temApplicationStatus = false;
      this.Application = false, // 基地详情弹框
			this.ProjectModelShow = false;
			this.demandModelShow = false;
		},
    // 查询所有用户
    getAllUser: function () {
      let that = this;
      that.user = [];
      that.userId = '';
      let name = $('#name').val();
      that.$post(
        that.urls.getAllUser,
      {"userName": name,"pageNum": that.upage, "pageSize": that.usize }
      )
        .then(function(res) {
          if(res.success) {
          that.user = res.pageInfo.list;
            that.utotal = res.pageInfo.total;
            that.upage = res.pageInfo.pageNum;

          }
        })
    },
    checkUserId: function (id) {
      let that = this;
      that.userId = id;
      console.log(that.userId)
    },
    // init base
    initBase: function () {
      let that = this;
      // 基地展示数据
      that.$post(
        that.urls.basePage, {
          "pageNum": that.page,
          "pageSize": that.size ,"list": [2,4]
        }
      )
        .then(function(res) {
          if(res.success) {
            that.baseData = res.pageInfo.list;
            that.page = res.pageInfo.pageNum;
            that.total = res.pageInfo.total;
          }
        })
    },

    // 跳转到预览
    openUrl: function (url) {
      if(url == null || url == undefined || url == ''){
        layer.msg('暂无附件', {
          time: 3000, //3s后自动关闭
        });
        return;
      }
      window.open(this.thatUrl + url);
    },

    subStr: function (str) {
      if(str.length > 10){
        let s = str.substr(0, 7);
        return s+ '...';
      }else {
        return str;
      }
    },
    viewOut:function ( b) {
      this.temApplicationStatus = true;
      this.base = b;
    },
    delAtt: function () {
      this.FileUpload = [];
      this.reasonFile = '';

    }

	}
}
